# -*- coding: utf-8 -*-
__author__ = 'qxq'
import requests,json

def get_document(shipmentNo,env):
    if env == "uat":
        url = "http://47.96.53.33:8080/opt-ocs-business-service/document/" + shipmentNo
        url1 = "http://47.96.53.33:8080/opt-logistics/logistics-status/trace/sf/sync"
    else:
        url = "http://120.55.138.130/opt-ocs-business-service/document/" + shipmentNo
        url1 = "http://120.55.138.130:8080/opt-logistics/logistics-status/trace/sf/sync"
    print(url)
    res = requests.get(url)
    print(res.json(), '1')
    dict = res.json()
    if 'data' in dict:
        print("执行成功")
        print("data数据为"+ str(res.json()))
        #这里是解析requests返回的response（json格式），并提取想要的数据
        SerialNo = json.loads(res.text).get('data').get('logisticsDeliverDocument').get('logisticsSerialNo')
        expressSerialNo = json.loads(res.text).get('data').get('logisticsDeliverDocument').get('expressSerialNo')
        print(SerialNo,expressSerialNo)
        data1 = {
            "content": "<?xml version='1.0' encoding='UTF-8'?><Request service=\"RoutePushService\" lang=\"zh-CN\">"
                       "<Body><WaybillRoute id=\"%s\" mailno=\"444145069463\" orderid=\"%s\" acceptTime=\"2019-04-18 11:58:52\" acceptAddress=\"湘潭市\" remark=\"上门收件\" opCode=\"50\"/>"
                       "</Body></Request>" % (expressSerialNo, SerialNo)
        }
        print(data1)
        # 注意这里的json和data的区别
        resp = requests.post(url1, json=data1)
        print(resp.json())
        return resp.text
    else:
        print("执行失败")


if __name__ == '__main__':
    get_document("I2019082814418720842984", "fat")


